package com.paperobot.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.paperobot.dao.AdminDao;
import com.paperobot.model.Admin;

@Repository("userService")
public class UserServiceImpl implements UserService{
	
	protected final Logger logger = LoggerFactory.getLogger(getClass());
	
	private AdminDao adminDao;

	@Resource
	public void setAdminDao(AdminDao adminDao) {
		this.adminDao = adminDao;
	}
	
	public Long addAdmin(Admin admin) {
		try {
			return adminDao.addAdmin(admin);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return -1L;
	}

	public Admin getAdmin(String userName) {
		Admin admin = null;
		try {
			admin = adminDao.getAdmin(userName);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return admin;
	}

	public List<Admin> getAdminList(int type) {
		List<Admin> adminList = null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("type", type);
		
		try {
			adminList = adminDao.getAdminList(map);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return adminList;
	}

	public List<Admin> getAdminList(int type, boolean status) {
		List<Admin> adminList = null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("type", type);
		map.put("status", status?1:0);
		
		try {
			adminList = adminDao.getAdminList(map);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return adminList;
	}

	public int updateAdmin(Admin admin) {
		try {
			return adminDao.updateAdmin(admin);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return -1;
	}

}












